//
//  UIImageView+Block.m
//  MeiDa
//
//  Created by zfc on 2019/10/25.
//  Copyright © 2019年 depelec. All rights reserved.
//

#import "UIImageView+Block.h"

static const char imageVBlock;


@implementation UIImageView (Block)

@dynamic block;


- (void)setBlock:(ImageViewTapBlock)block {

    objc_setAssociatedObject(self, &imageVBlock, block, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];

    dispatch_async(dispatch_get_main_queue(), ^{
        self.userInteractionEnabled = YES;
        [self addGestureRecognizer:tap];
    });

}


- (void) tapAction {
    if (self.block){
        self.block(self);
    }
}

-(ImageViewTapBlock)block {
    return objc_getAssociatedObject(self, &imageVBlock);
}

@end
